﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestorDeFlotasDesktop.Modelo;
// Objetos SQL
using System.Data.SqlClient;

namespace GestorDeFlotasDesktop
{
    public partial class MainForm : Form
    {
        private Login.Login loginForm;
        private Form activeForm = null;

        public MainForm(Login.Login loginForm)
        {
            InitializeComponent();
            this.loginForm = loginForm;
            this.loginForm.Hide();
            this.filterOptions();
        }

        private void filterOptions()
        {
            if(!Login.Login.permisosList.Contains(1))
            {
                clienteToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(2))
            {
                rolToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(3))
            {
                usuarioToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(4))
            {
                autoToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(5))
            {
                relojToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(6))
            {
                choferToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(7))
            {
                turnoToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(8))
            {
                asignarChoferAutoToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(9))
            {
                nuevoToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(10))
            {
                rendicionToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(11))
            {
                facturacionToolStripMenuItem.Visible = false;
            }
            if (!Login.Login.permisosList.Contains(12))
            {
                reportesToolStripMenuItem.Visible = false;
            }
            
        }

        public void openForm(Form form){
            //lo borro de la coleccion de controles, y seteo la activa a null
            if (this.activeForm != null) {
                this.Controls.Remove(this.activeForm);
                this.activeForm.Dispose();
                this.activeForm = null;
            }
            this.activeForm = form;
            this.activeForm.TopLevel = false;
            this.activeForm.Dock = DockStyle.Fill;
            this.activeForm.FormBorderStyle = FormBorderStyle.None;
            this.activeForm.Visible = true;
            this.Controls.Add(this.activeForm);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            using (SqlConnection con = Modelo.Modelo.createConnection())
            {
                try
                {
                    Modelo.Modelo.openConnection(con);
                    toolStripStatusLabel1.Text = "Conectado.";
                }
                catch (Exception)
                {
                    toolStripStatusLabel1.Text = "Sin Conexion !!";
                    toolStripStatusLabel1.ForeColor = Color.Red;
                }
                finally
                {
                    Modelo.Modelo.closeConnection(con);
                }
            }
                

        }

        #region Salir
        private void salirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion

        #region Formulario Cliente

        private void altaClienteLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmCliente.AbmCliente(Modelo.FormActions.Actions.Alta, ""));
        }

        private void bajaClienteLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionClienteLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        #region Formulario Rol
        private void altaRolLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmRol.AbmRol(Modelo.FormActions.Actions.Alta));
        }

        private void bajaRolLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionRolLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        #region Formulario Usuario
        private void altaUsuarioLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmUsuario.AbmUsuario(Modelo.FormActions.Actions.Alta));
        }

        private void bajaUsuarioLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionUsuarioLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        #region Formulario Auto
        private void altaAutoLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmAuto.AbmAuto(Modelo.FormActions.Actions.Alta));
        }

        private void bajaAutoLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionAutoLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        #region Formulario Reloj
        private void altaRelojLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmReloj.AbmReloj(Modelo.FormActions.Actions.Alta));
        }

        private void bajaRelojLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionRelojLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        #region Formulario Chofer
        private void altaChoferLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmChofer.AbmChofer(Modelo.FormActions.Actions.Alta, ""));
        }

        private void bajaChoferLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionChoferLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        #region Formulario Turno-Tarifa
        private void altaTurnoLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmTarifa.AbmTurno(Modelo.FormActions.Actions.Alta, ""));
        }

        private void bajaTurnoLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Baja));
        }

        private void modificacionTurnoLink_Click(object sender, EventArgs e)
        {
            this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Modificacion));
        }
        #endregion

        private void nuevoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openForm(new RegistrarViaje.RegistrarViajes());
        }

        private void asignarChoferAutoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openForm(new AsignChoferAuto.AsignChoferAuto());
        }

        private void facturacionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openForm(new Facturar.Facturar());
        }

        private void rendicionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openForm(new RendirViajes.RendierViajes());
        }

        private void reportesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.openForm(new Listado.Listado());
        }

    }
}
